package com.software.motorcade.dao;

import java.security.NoSuchAlgorithmException;

public class MotorcadeTransaction {

	private MotorcadeDao motorcadeDao;
	
	public MotorcadeDao getMotorcadeDao() {
		return motorcadeDao;
	}

	public void setMotorcadeDao(MotorcadeDao motorcadeDao) {
		this.motorcadeDao = motorcadeDao;
	}

	public boolean login(String email,String password){
		Motorcade motorcade = new Motorcade();
		motorcade.setEmail(email);
		motorcade.setPassword(password);
		Motorcade m = motorcadeDao.queryMotorcade(motorcade);
		if(m != null){
			if(password.equals(m.getPassword())){
				return true;
			}
		}
		return false;
	}
	
	/**
	 * 
	 * 前提：判断账户是否已经被注册
	 * @param username
	 * @param password
	 * @param email
	 * @param description
	 * @param phone
	 * @return
	 * @throws NoSuchAlgorithmException
	 */
	public boolean register(String name,String password, String email,String phone,String description){
		Motorcade motorcade = new Motorcade();
		motorcade.setEmail(email);
		motorcade.setPassword(password);
		motorcade.setPhone(phone);
		motorcade.setName(name);
		motorcade.setDescription(description);
		
		Motorcade m = motorcadeDao.queryMotorcade(motorcade);
		if(m != null){
			return false;
		}
		try{
			motorcadeDao.addMotorcade(motorcade);
			return true;
		}catch(Exception e){
			return false;
		}	
	}
}
